package com.mall.seckill_mall.utils;

import com.mall.seckill_mall.common.Result;
import com.mall.seckill_mall.enums.CodeMessage;

public class ResultUtil {
    @SuppressWarnings("unchecked")
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(CodeMessage.SUCCESS.getCode());
        result.setMessage(CodeMessage.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    @SuppressWarnings("unchecked")
    public static Result success(CodeMessage codeMessage, Object data) {
        Result result = new Result();
        result.setCode(codeMessage.getCode());
        result.setMessage(codeMessage.getMessage());
        result.setData(data);
        return result;
    }

    public static Result success() {
        return success(null);
    }

    public static Result error(CodeMessage codeMsg) {
        Result result = new Result();
        result.setCode(codeMsg.getCode());
        result.setMessage(codeMsg.getMessage());
        return result;
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
}
